package com.cjl.dental_clinic.base;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.net.HttpURLConnection;

@Data
@Accessors(chain = true)
public class ResVo<T> implements Serializable {
    private static int SUCESS_CODE  =1;
    private int state;
    private String msg;
    private T data;
    private boolean success;

    public static <T> ResVo<T> ok() {
        return fillRestVo(SUCESS_CODE, null, null, true);
    }

    public static <T> ResVo<T> ok(String msg, T data) {
        return fillRestVo(SUCESS_CODE, msg, data, true);
    }

    public static <T> ResVo<T> ok(T data) {
        return fillRestVo(SUCESS_CODE, null, data, true);
    }

    public static <T> ResVo<T> error() {
        return fillRestVo(500, null, null, false);
    }

    public static <T> ResVo<T> error(String msg, T data) {
        return fillRestVo(500, msg, data, false);
    }
    public static <T> ResVo<T> error(int state,String msg) {
        return fillRestVo(state, msg, null, false);
    }

    public static <T> ResVo<T> error(T data) {
        return fillRestVo(500, null, data, false);
    }

    public static <T> ResVo<T> fillRestVo(int state, String msg, T data, boolean success) {
        return new ResVo<T>().setState(state).setMsg(msg)
                .setData(data).setSuccess(success);
    }
}
